package com.gomoku.backend.controller.pk;

import com.gomoku.backend.service.pk.StartGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
public class StartGameController {
    @Autowired
    private StartGameService startGameService;

    @PostMapping("/pk/startgame/")
    public String startGame(@RequestParam MultiValueMap<String,String> data){
        Integer aId = Integer.valueOf(Objects.requireNonNull(data.getFirst("aId")));
        Integer bId = Integer.valueOf(Objects.requireNonNull(data.getFirst("bId")));
        return startGameService.startGame(aId,bId);
    }
    @PostMapping("/pk/startaigame/")
    public String startAIGame(@RequestParam MultiValueMap<String,String> data){
        Integer aId = Integer.valueOf(Objects.requireNonNull(data.getFirst("aId")));
        Integer botId = Integer.valueOf(Objects.requireNonNull(data.getFirst("botId")));
        return startGameService.startAIGame(aId,botId);
    }
}
